/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package genetic;

import java.awt.Point;
import java.util.ArrayList;
import reader.Data;
import reader.Filereader;

/**
 *
 * @author Ifun
 */
public class geneticMain {

    public static void main(String[] args) throws Exception {
        Filereader fr = new Filereader("dataset\\nursery - 6000an.arff");
        //Filereader fr = new Filereader("dataset\\nursery.arff");
        fr.doRead();
        Data data = fr.getData();
        
//        Individual best = new Individual();
//        GeneticAlgorithm ga = new GeneticAlgorithm();
//        
//        best = ga.GeneticAlgorithm(3, 23, 5, 50, 1, fr.getHeader(), data);
        

        Population pop = new Population(5, 23, fr.getHeader());
        pop.updateFitness(data);
        pop.updateProbability();
        pop.rankPopulation();
        float fraction = 0.5f;
        Population selection  = new Population();
        selection.society = pop.select(fraction);
        for (int i = 0; i < pop.society.size(); ++i) {
            System.out.println(pop.society.get(i).probability + " , " + pop.society.get(i).fitnessVal);
        }
        System.out.println("aaaa");
        for (int i = 0; i < selection.society.size(); ++i) {
            System.out.println(selection.society.get(i).probability + " , " + selection.society.get(i).fitnessVal);
        }
        System.out.println("bbbbbb");
        ArrayList<Point> cupid = pop.pairsIndividual(fraction);
        for(int i=0;i<cupid.size();++i)
        {
            System.out.println(cupid.get(i).x + " , " + cupid.get(i).y);
            System.out.println(pop.getSociety().get(cupid.get(i).x).getProbability() + " , " + pop.getSociety().get(cupid.get(i).y).getProbability());
        }
        System.out.println(pop.getMaxFitness());
        System.out.println("ccccccccc");
        System.out.println(selection.getSociety().size());
        System.out.println("dddddddd");
        for(int i=0;i<cupid.size();++i)
        {
            Individual[] childs = new Individual[2];
            childs[0] = new Individual();
            childs[1] = new Individual();
            childs = pop.getSociety().get(cupid.get(i).x).createChilds(pop.getSociety().get(cupid.get(i).y));
            selection.getSociety().add(childs[0]);
            selection.getSociety().add(childs[1]);
        }
//        System.out.println(selection.getSociety().size());
//        selection.updateFitness(data);
//        selection.updateProbability();
//        System.out.println("eeeeeeeeeeeee");
//        for (int i = 0; i < selection.society.size(); ++i) {
//            System.out.println(selection.society.get(i).probability + " , " + selection.society.get(i).fitnessVal);
//        }
//        System.out.println("ffffffffff");
//        int mutate = selection.mutationPop(90);
//        System.out.println(mutate);
//        if(mutate>-1)
//        {
//            selection.updateFitness(data);
//            selection.updateProbability();
//            System.out.println("ggggggggggg");
//            for (int i = 0; i < selection.society.size(); ++i) {
//                System.out.println(selection.society.get(i).probability + " , " + selection.society.get(i).fitnessVal);
//            }
//        }
        
    }
}
